﻿using DalatCooking.Core.Helper;
using DalatCooking.Core;
using DalatCooking.Core.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_Product_Picture : System.Web.UI.Page
{
    public int total = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

        // Response.Write(IsPublished.ToString());

    }
    protected override void OnInit(EventArgs e)
    {
        BinData();

        base.OnInit(e);
    }

    public int ProductID
    {
        get
        {
            if (Request.QueryString["ProductID"] != null)
                return ConvertObject.ToInt(Server.HtmlEncode(Request.QueryString["ProductID"]));
            else return -1;
        }
    }
    bool IsPublished
    {
        get { return ConvertObject.ToBool(Request.QueryString["IsPublished"] != null); }
    }

    public bool Published
    {
        get
        {
            if (Request.QueryString["IsPublished"] != null)
                return ConvertObject.ToBool(Request.QueryString["IsPublished"]);

            return false;
        }
    }
    void BinData()
    {
        int pageSize = 10;
        if (Request.Cookies["postPageSize"] != null)
        {
            pageSize = ConvertObject.ToInt(Server.HtmlEncode(Request.Cookies["postPageSize"].Value));
        }
        else
        {
            pageSize = 10;// Settings.SettingInt("site.pagesize");
        }

        int pageNum = 1;

        if (Request.QueryString[PagingControl1.QueryStringKey] != null)
        {
            pageNum = ConvertObject.ToInt(Server.HtmlEncode(Request.QueryString[PagingControl1.QueryStringKey]));
        }
        else pageNum = 1;

        //Repeater1.DataSource =  BusinessLayer.Entities.Menu.All();



        if (ProductID != -1)
        {
           // rpt.DataSource = ProductImage.PagingSql_ByProductID(pageSize, pageNum, out total, ProductID);
        }
        else if (IsPublished)
        {
            rpt.DataSource = CourseImageManager.PagingSql(pageSize, pageNum, out total);

        }
        else rpt.DataSource = CourseImageManager.PagingSql(pageSize, pageNum, out total);
        //rpt.DataSource = Contents.All();
        rpt.DataBind();

        PagingControl1.TotalPage = total;
        PagingControl1.CurrentPage = pageNum;
        PagingControl1.PageSize = pageSize;


        PagingControl2.TotalPage = total;
        PagingControl2.CurrentPage = pageNum;
        PagingControl2.PageSize = pageSize;

    }
    public string GetProductName(object pId)
    {
        Course p = CourseManager.Single(ConvertObject.ToInt(pId));
        return (p != null) ? p.Name : "";
    }
    public int Count()
    {
        return total;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtServiceID.Text) && !string.IsNullOrEmpty(txtImageUrl.Text))
        {
            CourseImage s = new CourseImage();
            s.CourseID = ConvertObject.ToInt(txtServiceID.Text);
            s.ImageUrl = txtImageUrl.Text;
            s.Alt = txtAlt.Text;
            s.Title = txtTitle.Text;
            s.IsPublished = chkIsPublished.Checked;
            bool rs = CourseImageManager.Insert(s);
            if (rs )
                Response.Redirect(Request.Url.AbsolutePath);
            Response.Write(rs);
        }
        else Response.Write(txtServiceID.Text);
    }
}